<template>
  <view class="search-component">
    <view class="search-layout" v-if="inputType == 1">
      <view class="search-box">
        <view class="input-left">
          <text class="iconfont icon-weibiaoti--17"></text>
        </view>
        <view class="search-text-list" @click="inputType = 2">
          <swiper
            class="swiper"
            circular
            :vertical="true"
            :autoplay="true"
            :interval="5000"
            :duration="300"
          >
            <swiper-item>
              <view class="swiper-item uni-bg-red">京东·笔记本外接键盘</view>
            </swiper-item>
            <swiper-item>
              <view class="swiper-item uni-bg-green"
                >京东·68键键盘
                <text class="green-text">国家补贴</text>
              </view>
            </swiper-item>
            <swiper-item>
              <view class="swiper-item uni-bg-blue"
                >京东·联想小新Pro<text class="red-text">推荐</text></view
              >
            </swiper-item>
          </swiper>
        </view>
        <view class="input-right">
          <text class="iconfont icon-weibiaoti--45"></text>
          <view class="search-btn">搜索</view>
        </view>
      </view>
    </view>

    <view class="search-layout bg" v-if="inputType == 2">
      <view class="search-box-flex">
        <view class="icon-box">
          <text
            class="iconfont icon-weibiaoti--10"
            @click="inputType = 1"
          ></text>
        </view>
        <input
          type="text"
          class="search-input"
          v-model="inputValue"
          placeholder="笔记本外接键盘"
          placeholder-class="placeholder-style"
          :focus="true"
        />
        <view class="input-right">
          <text
            v-if="inputValue"
            class="iconfont icon-weibiaoti--13"
            @click="clearInputValue"
          ></text>
          <text class="iconfont icon-weibiaoti--45"></text>
          <view class="search-btn">搜索</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { defineComponent, reactive, toRefs } from "vue";
export default defineComponent({
  name: "search004",
  props: {},
  components: {},
  setup() {
    const data = reactive({
      inputType: 1,
      inputValue: "",
    });

    const clearInputValue = () => {
      data.inputValue = "";
    };
    return {
      clearInputValue,
      ...toRefs(data),
    };
  },
});
</script>

<style scoped lang="less">
.search-component {
  .search-layout {
    display: flex;
    justify-content: space-between;
    height: 90rpx;
    padding: 10rpx 20rpx;
    box-sizing: border-box;
    background: linear-gradient(to bottom, #ff0f23, #fff);
    &.bg {
      background: #ff0f23;
    }
    .search-box {
      flex: 1;
      position: relative;

      .search-text-list {
        height: 100%;
        line-height: 64rpx;
        box-sizing: border-box;
        color: #000;
        border-radius: 15rpx;
        background: #fff;
        border: 3rpx solid #ff0f23;
        padding-left: 80rpx;
        overflow: hidden;
        .swiper {
          height: 100%;
          .red-text,
          .green-text {
            color: #fff;
            height: 24rpx;
            line-height: 24rpx;
            background: #ff0f23;
            padding: 0 8rpx;
            border-radius: 6rpx;
            font-size: 20rpx;
            margin-left: 10rpx;
            font-weight: 700;
          }
          .green-text {
            background: #00b928;
            font-weight: 400;
          }
          .swiper-item {
            display: flex;
            align-items: center;
            font-size: 26rpx;
            font-weight: 300;
          }
        }
      }
      .input-left {
        display: flex;
        align-items: center;
        line-height: 50rpx;
        position: absolute;
        top: 10rpx;
        left: 20rpx;
        .icon-weibiaoti--17 {
          font-size: 36rpx;
          margin-right: 20rpx;
          color: #ff0f23;
        }
      }
      .input-right {
        display: flex;
        align-items: center;
        position: absolute;
        top: 10rpx;
        right: 10rpx;
        .icon-weibiaoti--45 {
          font-size: 40rpx;
          margin-right: 20rpx;
          color: #999;
        }
        .search-btn {
          border-left: 1rpx solid #ff0f23;
          height: 50rpx;
          line-height: 50rpx;
          padding: 0 20rpx;
          font-size: 30rpx;
          font-weight: 600;
          color: #ff0f23;
        }
      }
    }
  }
  .search-box-flex {
    position: relative;
    display: flex;
    justify-content: space-between;
    width: 100%;

    .icon-box {
      line-height: 70rpx;
      width: 50rpx;
      overflow: hidden;
      text-align: left;
      transition: 0.3s;
      .icon-weibiaoti--10 {
        font-size: 40rpx;
        color: #fff;
      }
    }
    .search-input {
      flex: 1;
      height: 100%;
      width: 100%;
      padding-left: 20rpx;
      box-sizing: border-box;
      color: #000;
      border-radius: 15rpx;
      background: #fff;
      border: 3rpx solid #ff0f23;
      overflow: hidden;
      font-size: 26rpx;
      font-weight: 300;
      //   placeholder样式修改
      .placeholder-style {
        color: #777;
      }
    }
    .input-right {
      display: flex;
      align-items: center;
      position: absolute;
      top: 10rpx;
      right: 10rpx;
      .icon-weibiaoti--45 {
        font-size: 40rpx;
        margin-right: 20rpx;
        color: #999;
      }
      .icon-weibiaoti--13 {
        font-size: 30rpx;
        margin-right: 30rpx;
        margin-top: 2rpx;
        color: #999;
      }
      .search-btn {
        border-radius: 15rpx;
        height: 50rpx;
        line-height: 50rpx;
        padding: 0 20rpx;
        font-size: 28rpx;
        font-weight: 500;
        color: #fff;
        background: #ff0f23;
      }
    }
  }
}
</style>
